//
//  AXspellFirstCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/12.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXspellFirstCell.h"
#import "UIImageView+WebCache.h"

@implementation AXspellFirstCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatView];
      
    }
    return self;
}


- (void)creatView {
    
    self.goodsImageview = [[UIImageView alloc]init];
    /** 图片比例切 */
    self.goodsImageview.contentMode =UIViewContentModeScaleAspectFill;
    self.goodsImageview.clipsToBounds=YES;//
    [self.contentView addSubview:self.goodsImageview];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = FONT_FOURTEEN;
    self.titleLabel.textColor = COLOR_DIV;
    [self.contentView addSubview:self.titleLabel];
    
    self.priceLabel = [[UILabel alloc]init];
    self.priceLabel.font = FONT_FOURTEEN;
    self.priceLabel.textColor = COLOR_ORG;
    [self.contentView addSubview:self.priceLabel];
    
  
    
    self.stockLabel = [[UILabel alloc]init];
    self.stockLabel.font = FONT_FOURTEEN;
    [self.contentView addSubview:self.stockLabel];
    
}

- (void)setlayout {
    
    self.goodsImageview.sd_layout
    .leftSpaceToView(self.contentView, 0)
    .topSpaceToView(self.contentView, 0)
    .widthIs(SCREEN_WIDTH)
    .heightIs(200);
    
    self.titleLabel.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.goodsImageview, 10)
    .widthIs((SCREEN_WIDTH-30)/2)
    .autoHeightRatio(0)
    .minHeightIs(30);
    
    self.stockLabel.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(self.goodsImageview, 10)
    .widthIs(120)
    .heightIs(30);
    
    self.priceLabel.sd_layout
    .rightSpaceToView(self.stockLabel, 10)
    .topSpaceToView(self.goodsImageview, 10)
    .widthIs(60)
    .heightIs(30);
    
    [self setupAutoHeightWithBottomView:self.stockLabel bottomMargin:10];
    
    
}

- (void)setModel:(AXspellFirstModel *)model {
    
    _model = model;
    
    [self.goodsImageview sd_setImageWithURL:[NSURL URLWithString:_model.groupActivityLogo] placeholderImage:[UIImage imageNamed:@"placeHold"]];
    self.titleLabel.text = _model.groupActivityTitle;
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",_model.groupPrice];
   // self.stockLabel.text = [NSString stringWithFormat:@"剩余库存%@",_model.groupActivityStock];
    
    /** 富文本 */
    NSMutableAttributedString  *timeString = [[  NSMutableAttributedString  alloc]init];
    NSAttributedString *timeStr = [[ NSAttributedString alloc]initWithString:@"剩余库存: " attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:COLOR_Gray}];
    [timeString appendAttributedString:timeStr];
    NSAttributedString *str2 = [[ NSAttributedString alloc]initWithString:_model.groupCurrentStock attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor orangeColor]}];
    [timeString appendAttributedString:str2];
    self.stockLabel.attributedText = timeString;//把字符串加到prepareLessonLabel上
    
    [self setlayout];
    
}

@end
